/**
 * 
 */
package com.nikolvas.interpolation;

/**
 * @author vnikolenko
 *
 */
public class LinearInterpolator {

	public static IFunction interpolate(Pair p1, Pair p2){
		float k = (p2.getY()-p1.getY()) / (p2.getX() - p1.getX());
		float b = (p2.getX()*p1.getY()-p1.getX()*p2.getY()) / (p2.getX() - p1.getX());
		return new LinearFunction(k, b);		
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Pair p1 = new Pair(4.9f, 56);
		Pair p2 = new Pair(4.8f, 59);
		IFunction f = interpolate(p1, p2);
		System.out.println(Math.round(f.getY(4.84f)));		
	}
	
	

}
